package com.hbnu.test.www.net;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP_server01 {
    public static void main(String[] args) {
//        1.创建服务端socket，并监听端口
        try (ServerSocket serverSocket = new ServerSocket(6666);Socket socket = serverSocket.accept();) {//2.获取客户端连接(socket)
            //3.获取流资源，准备接受客户端所发送数据
            byte[] bytes = new byte[1024];
            InputStream inputStream = socket.getInputStream();
            //4.处理资源

            int len = inputStream.read(bytes);
//            int len = 0;
//            int temp = 0;
//
            System.out.println("接收信息为:" + new String(bytes, 0, len));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        //5.关闭流资源和socket

    }
}
